﻿using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordOpenXmlClassLibrary.Entity;
using WordOpenXmlClassLibrary.Enum;

namespace WordOpenXmlClassLibrary
{

    /// <summary>
    /// 类库功能管理器
    /// </summary>
    public class GenerateManager
    {
        private string filePath;

        public string FilePath { get => filePath; set => filePath = value; }

        public void CreateObjectiveItem(BlockOption opt)
        {
            using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(FilePath, WordprocessingDocumentType.Document))
            {
                // 创建基础文档结构
                Generater generater = new Generater(wordprocessingDocument);

                string optionSequence = opt.OptionSequence;// 选项序列
                int numberOfQuestions = opt.NumberOfQuestions;// 题目数量
                int startingQuestionNumber = opt.StartingQuestionNumber;// 起始题号
                int topicGroupDirection = opt.TopicGroupDirection;// 题组方向


                PageOrientationValues orientationValue = new PageOrientationValues();
                switch (topicGroupDirection)
                {
                    case (int)PageOrientationValues.Landscape:
                        orientationValue = PageOrientationValues.Landscape;
                        break;
                    case (int)PageOrientationValues.Portrait:
                        orientationValue = PageOrientationValues.Portrait;
                        break;
                    default:
                        orientationValue = PageOrientationValues.Landscape;
                        break;
                }
                generater.ObjectiveItem(optionSequence.Split(','), numberOfQuestions, startingQuestionNumber, orientationValue);
                //// 设置页面大小：默认A4
                generater.SectionProperties(PageSizeValues.A4, PageOrientationValues.Landscape);
                // 保存文档
                generater.Save();
            }
        }
    }
}
